package com.justgame.project.service.just.controller;

import com.justgame.project.base.annotation.ProtectAccess;
import com.justgame.project.cloud.common.constant.Result;
import com.justgame.project.service.api.dto.JustGameCommentDTO;
import com.justgame.project.cloud.common.entity.PageRequest;
import com.justgame.project.service.just.service.JustGameCommentService;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/just/game-comment")
@AllArgsConstructor
public class JustGameCommentController {

    private final JustGameCommentService gamePlatformService;

    @GetMapping("/get-page")
    public Result<?> getCommentList(PageRequest pageRequest,
                                    @RequestParam String gameId, HttpServletRequest request) {
        JustGameCommentDTO dto = new JustGameCommentDTO();
        dto.setGameId(gameId);
        dto.setType(1);
        return Result.OK(gamePlatformService.getList(pageRequest, dto));
    }

    @PostMapping("/save-comment")
    @ProtectAccess(value = 3L,message = "您提交的速度太快了，稍等一下吧！")
    public Result<?> addComment(@Valid @RequestBody JustGameCommentDTO dto) {
        return Result.OK(gamePlatformService.save(dto));
    }

    @DeleteMapping("/delete")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> deleteComment(@RequestBody JustGameCommentDTO dto) {
        return Result.OK(gamePlatformService.Delete(dto));
    }

    @PostMapping("/updateById")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> updateCommentById(@RequestBody JustGameCommentDTO dto) {
        return Result.OK(gamePlatformService.updateById(dto));
    }

}
